package month4.day13;

import java.util.Scanner;

public class PCText {
    public static void main(String[] args) {
        System.out.println("新电脑采购成功请输入型号：");
        PC pc = new PC();
        Scanner in = new Scanner(System.in);
        pc.setBrand(in.next());
        System.out.println("请输入颜色：");
        pc.setColor(in.next());
        System.out.println("请输入分辨率：");
        pc.setSize(in.next());
        System.out.println("请输入硬盘容量：");
        pc.setHardDiskcapacity(in.nextInt());
        boolean a1 = true;
        boolean a2 = true;
        boolean a3 = true;
        int fp = 0;//分盘数
        ck:
        while (true) {
            System.out.println("1:格式化，2：安装操作系统，3：启动，4：安装软件，5：下载软件，6：查看各盘情况，9：退出");
            int num = in.nextInt();
            while (a1) {
                if (num == 3) {
                    System.out.println("启动成功");
                    a1 = false;
                } else {
                    System.out.println("请先启动");
                }
                continue ck;
            }
            fenpei:while (a2) {
                if (num == 1) {
                    System.out.println("计划分为几个盘");
                    fp = in.nextInt();
                    System.out.println("请分别输入" + fp + "个盘符");
                    for (int i = 0; i < fp; i++) {
                        Dish dish=new Dish(in.next());
                        pc.dishes[i]=dish;
                    }
                    int sum = 0;

                    for (int i = 0; i < fp; i++) {
                        System.out.println("请输入第" + (i + 1) + "个盘的大小");
                        int daxiao = in.nextInt();
                        sum = sum + daxiao;
                        if (sum > pc.getHardDiskcapacity()) {
                            System.out.println("硬盘容量不足，分配失败，请重新分配");
                            continue fenpei;
                        }
                        pc.dishes[i].setCapacity(daxiao);
                        pc.dishes[i].setRemaining(daxiao);
                    }
                    a2 = false;
                    System.out.println("格式化成功");
                } else {
                    System.out.println("请先格式化");
                }
                continue ck;
            }
            while (a3) {
                if (num == 2) {
                    System.out.println("请选择操作系统，win7/win10/win11");
                    pc.setOS(in.next());
                    az:
                    while (true) {
                        System.out.println("请选择安装的盘：");
                        String azp = in.next();
                        int i = 0;
                        for (; i < fp; i++) {
                            if (pc.dishes[i].getName().equals(azp)) {
                                if (pc.dishes[i].getRemaining() >= 7000) {
                                    System.out.println("安装成功，大小为7000M");
                                    pc.dishes[i].setRemaining(pc.dishes[i].getRemaining() - 7000);
                                } else {
                                    System.out.println("所选磁盘容量不足，请重新选择");
                                    continue az;
                                }
                                a3 = false;
                                break az;
                            }
                        }
                        if (i == fp)
                            System.out.println("没有这个盘，请重新输入");
                    }
                } else {
                    System.out.println("请先安装系统");
                }
                continue ck;
            }


            if (num == 4) {
                System.out.println("1：普通软件，2：下载软件");
                int ruanjian = in.nextInt();
                System.out.println("软件名称：");
                String name = in.next();
                System.out.println("软件大小：");
                double capacity = in.nextDouble();
                System.out.println("软件安装位置：");
                String dish = in.next();
                int i = 0;
                for (; i < fp; i++) {
                    if (pc.dishes[i].getName().equals(dish)) {
                        if (pc.dishes[i].getRemaining() >= capacity) {
                            if (ruanjian == 1) {
                                DeneralSoftware deneralSoftware=new DeneralSoftware(name,capacity,dish);
                                pc.dishes[i].softwares[pc.dishes[i].soft]=deneralSoftware;
                                pc.dishes[i].soft++;
                            } else {
                                DownloadSoftware downloadSoftware=new DownloadSoftware(name,capacity,dish);
                                pc.dishes[i].downloadSoftwares[pc.dishes[i].down]=downloadSoftware;
                                pc.dishes[i].down++;
                            }
                            System.out.println("安装成功，大小为"+capacity+"M");
                            pc.dishes[i].setRemaining(pc.dishes[i].getRemaining() - capacity);
                            break;
                        } else {
                            System.out.println("所选磁盘容量不足，请重新选择");
                            break;
                        }
                    }
                }
                if (i == fp)
                    System.out.println("安装失败，所选磁盘不存在");

            } else if (num == 6) {
                System.out.println("请输入盘符：");
                String dish = in.next();
                for (int i = 0; i < fp; i++) {
                    if (pc.dishes[i].getName().equals(dish)) {
                        System.out.println("安装软件如下：");
                        for(int j=0;j<pc.dishes[i].soft;j++){
                            System.out.println(pc.dishes[i].softwares[j].toString());
                        }
                        for(int j=0;j<pc.dishes[i].down;j++){
                            System.out.println(pc.dishes[i].downloadSoftwares[j].toString());
                        }
                    }
                }

            } else if (num == 5) {
                System.out.println("请选择一个下载软件：");
                for(int i=0;i<fp;i++){
                    for(int j=0;j<pc.dishes[i].down;j++){
                        System.out.println(pc.dishes[i].downloadSoftwares[j].getName());
                    }
                }
                String name=in.next();
                int i=0;
                qidon:for(;i<fp;i++){
                    for(int j=0;j<pc.dishes[i].down;j++){
                        if(pc.dishes[i].downloadSoftwares[j].getName().equals(name)){
                            System.out.println("启动成功");
                            break qidon;
                        }
                    }
                }
                if(i==fp) {
                    System.out.println("找不到改下载软件");
                    continue  ;
                }
                System.out.println("下载软件名字：");
                String na = in.next();
                System.out.println("软件大小：");
                double capacity = in.nextDouble();
                System.out.println("软件安装位置：");
                String dish = in.next();
                int j = 0;
                anzhuang:for (; j < fp; j++) {
                    if (pc.dishes[j].getName().equals(dish)) {
                        if (pc.dishes[j].getRemaining() >= capacity) {
                            DeneralSoftware deneralSoftware=new DeneralSoftware(na,capacity,dish);
                            pc.dishes[j].softwares[pc.dishes[j].soft]=deneralSoftware;
                            pc.dishes[j].soft++;
                            System.out.println("安装"+na+"成功!");
                            break anzhuang;
                        }
                    }
                }
                if(j==fp)
                    System.out.println("安装失败");
            } else if (num == 9) {
                return;
            } else if (num == 1) {

            } else if (num == 2) {

            } else if (num == 3) {

            }

        }
    }
}
